package com.faiz.algorithm;

public class BinarySearch {

    /**
     * 查询区间内的某一个数
     * @param nums 待查询数组
     * @return 查找的结果
     */
    public static int searchTarget(int[] nums, int target) {
        int l = 0, r = nums.length - 1;

        while (l <= r) {
            int m = l + (r - l) / 2;
            if (nums[m] == target) {
                return m;
            } else if (nums[m] > target) {
                r = m - 1;
            } else if (nums[m] < target) {
                l = m + 1;
            }
        }
        return -1;
    }

    /**
     * 查找一个可重复出现的数的区间
     * @param nums 待产找的数组
     * @param target 目标
     * @return 查找结果
     */
    public static int leftBound(int[] nums, int target) {
        return -1;
    }

    public static int rightBound(int[] nums, int target) {
        return -1;
    }

    public static void main(String[] args) {

    }
}
